package utilities;

import java.util.*;

public class TestEntity implements Archiveable {
	String name;
	TestStatSet stats;
	List<TestAbility> abilities;
	
	public TestEntity() {
		this.name = "Entity";
		this.stats = new TestStatSet();
		this.abilities = new ArrayList<TestAbility>();
		this.abilities.add(new TestAbility());
		this.abilities.add(new TestAbility());
		this.abilities.add(new TestAbility());
	}
	
	public Archive save() {
		Archive archive = new JSONArchive();
		
		archive.putAttribute("name", this.name);
		
		archive.putClassName("stats", this.stats.getClass().getName());
		archive.putOneRelationship("stats", this.stats);
		
		archive.putManyRelationship("abilities", this.abilities);
		
		return archive;
	}
	
	public void load(Archive archive) {
		this.name = archive.getAttribute("name");
		
		Archive statsArchive = archive.getOneRelationship("stats");
		this.stats = (TestStatSet)ModelFactory.getInstance().createInstanceWithClassName(archive.getClassName("stats"));
		this.stats.load(statsArchive);
		
		List<Archive> list = archive.getManyRelationship("abilities");
		this.abilities = new ArrayList<TestAbility>(list.size());
		for (Archive a : list) {
			TestAbility ability = new TestAbility();
			ability.load(a);
			
			this.abilities.add(ability);
		}
	}
	
}
